package com.efeichong.project.domain.entity.db;

import com.efeichong.audit.InsertDefault;
import com.efeichong.audit.UpdateDefault;
import com.efeichong.common.config.AuditorHolder;
import com.efeichong.common.domain.BaseEntity;
import com.google.common.collect.Lists;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;


/**
 * @author
 * @date 2020/11/25
 * @description 数据字典表
 */
@Setter
@Getter
@Entity
@Table(indexes = {
        @Index(name = "PRIMARY", columnList = "id", unique = true),
        @Index(name = "dict_type", columnList = "type", unique = true),
})
public class SysDict extends BaseEntity {
    /**
     * 字典名称
     */
    @Column(name = "[name]", columnDefinition = "varchar(100) comment'字典名称'")
    private String name;

    /**
     * 字典类型
     */
    @Column(name = "[type]", columnDefinition = "varchar(100) comment'字典类型'")
    private String type;

    /**
     * 创建者
     */
    @InsertDefault(val = AuditorHolder.class)
    @JoinColumn(name = "[create_by]")
    @ManyToOne(fetch = FetchType.LAZY)
    private SysUser createBy;

    /**
     * 更新者
     */
    @UpdateDefault(val = AuditorHolder.class)
    @JoinColumn(name = "[update_by]")
    @ManyToOne(fetch = FetchType.LAZY)
    private SysUser updateBy;

    /**
     * 备注
     */
    @Column(name = "[remark]", columnDefinition = "varchar(500) comment'备注'")
    private String remark;

    /**
     * 字典明细列表
     */
    @OneToMany(mappedBy = "dict", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<SysDictDetail> dictDetails = Lists.newArrayList();
}
